package com.shrct.businessprocess.project.impl;

import com.shrct.businessprocess.project.RCProject;
import com.shrct.businessprocess.project.RCProjectProcessEvent;
import com.shrct.businessprocess.project.RCProjectProcessEventCriteria;
import com.shrct.businessprocess.project.RCProjectProcessEventStatus;
import edu.fudan.langlab.domain.security.User;
import edu.fudan.mylang.pf.query.HQLBasedPagedQueryCriteria;
import java.util.Date;
import org.hibernate.Query;

public class RCProjectProcessEventCriteriaImpl extends HQLBasedPagedQueryCriteria<RCProjectProcessEvent> implements RCProjectProcessEventCriteria {
  private RCProjectProcessEventStatus status;
  
  public RCProjectProcessEventStatus getStatus() {
    return this.status;
  }
  
  public RCProjectProcessEventCriteria setStatus(final RCProjectProcessEventStatus status) {
    this.status = status;
    return this;			
    
  }
  
  private Date startDateFrom;
  
  public Date getStartDateFrom() {
    return this.startDateFrom;
  }
  
  public RCProjectProcessEventCriteria setStartDateFrom(final Date startDateFrom) {
    this.startDateFrom = startDateFrom;
    return this;			
    
  }
  
  private Date startDateTo;
  
  public Date getStartDateTo() {
    return this.startDateTo;
  }
  
  public RCProjectProcessEventCriteria setStartDateTo(final Date startDateTo) {
    this.startDateTo = startDateTo;
    return this;			
    
  }
  
  private RCProject project;
  
  public RCProject getProject() {
    return this.project;
  }
  
  public RCProjectProcessEventCriteria setProject(final RCProject project) {
    this.project = project;
    return this;			
    
  }
  
  private User executer;
  
  public User getExecuter() {
    return this.executer;
  }
  
  public RCProjectProcessEventCriteria setExecuter(final User executer) {
    this.executer = executer;
    return this;			
    
  }
  
  private Boolean isFinished;
  
  public Boolean getIsFinished() {
    return this.isFinished;
  }
  
  public RCProjectProcessEventCriteria setIsFinished(final Boolean isFinished) {
    this.isFinished = isFinished;
    return this;			
    
  }
  
  protected String buildHQLFrom() {
    return " from com.shrct.businessprocess.project.impl.RCProjectProcessEventImpl this  left join  this.bp.activities as activity ";
  }
  
  protected String buildHQLBody() {
    String hql = "where 1 = 1 ";
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getExecuter()) ){
    	hql += " and ((activity.executer) = (:executer))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getProject()) ){
    	hql += " and ((this.project) = (:project))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getStatus()) ){
    	hql += " and ((this.status) = (:status))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getStartDateFrom()) ){
    	hql += " and ((this.date) >= (:startDateFrom))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getStartDateTo()) ){
    	hql += " and ((this.date) <= (:startDateTo))" ;
    }
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getIsFinished()) ){
    	hql += " and ((this.bp.isFinished) = (:isFinished))" ;
    }
    return hql;
    
  }
  
  public void initOrderBys() {
    addOrder("this.date",edu.fudan.mylang.pf.query.OrderItem.DESC);
  }
  
  protected void fillParameter(final Query query) {
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getStatus())){
    	query.setParameter("status",getStatus()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getStartDateFrom())){
    	query.setParameter("startDateFrom",getStartDateFrom()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getStartDateTo())){
    	query.setParameter("startDateTo",getStartDateTo()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getProject())){
    	query.setParameter("project",getProject()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getExecuter())){
    	query.setParameter("executer",getExecuter()) ;
    }			
    if( !edu.fudan.mylang.pf.query.QueryUtil.isNull(getIsFinished())){
    	query.setParameter("isFinished",getIsFinished()) ;
    }			
    
  }
  
  protected Boolean isDistinct() {
    return true;
  }
  
  public RCProjectProcessEventCriteriaImpl() {
    initOrderBys();
  }
}
